package com.hmall.order.config;

import com.hmall.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DelayListener {
    @Autowired
    private IOrderService orderService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "delay.queue",durable = "true"),
            exchange = @Exchange(name ="delay.direct",delayed = "true"),
            key = "delay"
    ))
    public void listenDalayedQueue(String msg){
        log.info("接收到 delay.queue的延迟消息,orderId:{}",msg);
        Long orderId = Long.valueOf(msg);
        //取消订单
        orderService.cancelOrder(orderId);
    }
}